package com.pactera.jep.service.sys.web.controller;

import com.pactera.jep.orm.Filter;
import com.pactera.jep.orm.Order;
import com.pactera.jep.orm.Page;
import com.pactera.jep.web.controller.CrudController;
import com.pactera.jep.web.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pactera.jep.service.sys.model.DeviceLogin;
import com.pactera.jep.service.sys.service.DeviceLoginService;


/**
 *
 * @Author YouName
 * @Date Jan 12, 2021 10:10:47 AM
 */
@RestController
@RequestMapping("/devicelogin")
@Api(description = "登录设备表")
public class DeviceLoginController extends CrudController<DeviceLogin> {

    @Autowired
    DeviceLoginService deviceLoginService;

    @GetMapping("/{id}")
    @ApiOperation("查询登录设备表")
    public Result get(@PathVariable("id") String deviceId) {
        return Result.success(deviceLoginService.get(deviceId));
    }

    @RequestMapping("/queryAll")
    @ApiOperation("分页查询登录设备表")
    public Map<String, Object> queryAll(Page<DeviceLogin> page, Model model, HttpServletRequest httpServletRequest, @RequestBody DeviceLogin deviceLogin) {
        Page<DeviceLogin> pages = new Page<>();
        Map<String, Object> result = new HashMap<>();
        pages.setPageNumber(page.getPageNumber());
        pages.setPageSize(page.getPageSize());
        page = deviceLoginService.queryAll(pages, deviceLogin);
        result.put(RESULT_TOTAL, page.getTotal());
        result.put(RESULT_ROWS, page.getResult());
        return result;
    }

//    @DeleteMapping("/{id}")
//    @ApiOperation("删除登录设备表")
//    public Result delete(@PathVariable("id") String deviceId) {
//        return Result.success(deviceLoginService.deleteByPrimaryKey(deviceId));
//    }
//
//    @PostMapping("/save")
//    @ApiOperation("插入登录设备表")
//    public Result insert(@RequestBody DeviceLogin deviceLogin) {
//        return Result.success(deviceLoginService.insert(deviceLogin));
//    }
//
//    @PostMapping("/update")
//    @ApiOperation("更新登录设备表")
//    public Result update(@RequestBody DeviceLogin deviceLogin) {
//        return Result.success(deviceLoginService.update(deviceLogin));
//    }

    /**
     * 为列表页面做数据准备
     */
    @Override
    protected void prepareQuery(Page<DeviceLogin> page, List<Filter> filters, List<Order> orders, HttpServletRequest    request) {
        deviceLoginService.query(page, filters, orders);
    }
}